package com.itkim.YZUserInfo.service.impl;

import java.util.List;

import cn.hutool.core.lang.generator.SnowflakeGenerator;
import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.itkim.YZUserInfo.mapper.YzUserMapper;
import com.itkim.YZUserInfo.domain.YzUser;
import com.itkim.YZUserInfo.service.IYzUserService;
import com.ruoyi.common.core.text.Convert;

/**
 * 账号管理Service业务层处理
 * 
 * @author itkim
 * @date 2024-06-04
 */
@Service
public class YzUserServiceImpl implements IYzUserService 
{
    @Autowired
    private YzUserMapper yzUserMapper;

    @Autowired
    private SnowflakeGenerator snowflakeGenerator;

    /**
     * 查询账号管理
     * 
     * @param userId 账号管理主键
     * @return 账号管理
     */
    @Override
    public YzUser selectYzUserByUserId(Long userId)
    {
        return yzUserMapper.selectYzUserByUserId(userId);
    }

    /**
     * 查询账号管理列表
     * 
     * @param yzUser 账号管理
     * @return 账号管理
     */
    @Override
    public List<YzUser> selectYzUserList(YzUser yzUser)
    {
        return yzUserMapper.selectYzUserList(yzUser);
    }

    /**
     * 新增账号管理
     * 
     * @param yzUser 账号管理
     * @return 结果
     */
    @Override
    public int insertYzUser(YzUser yzUser)
    {
        yzUser.setCreateTime(DateUtils.getNowDate());
        yzUser.setUserId(snowflakeGenerator.next());
        return yzUserMapper.insertYzUser(yzUser);
    }

    /**
     * 修改账号管理
     * 
     * @param yzUser 账号管理
     * @return 结果
     */
    @Override
    public int updateYzUser(YzUser yzUser)
    {
        return yzUserMapper.updateYzUser(yzUser);
    }

    /**
     * 批量删除账号管理
     * 
     * @param userIds 需要删除的账号管理主键
     * @return 结果
     */
    @Override
    public int deleteYzUserByUserIds(String userIds)
    {
        return yzUserMapper.deleteYzUserByUserIds(Convert.toStrArray(userIds));
    }

    /**
     * 删除账号管理信息
     * 
     * @param userId 账号管理主键
     * @return 结果
     */
    @Override
    public int deleteYzUserByUserId(Long userId)
    {
        return yzUserMapper.deleteYzUserByUserId(userId);
    }

    /**
     * 导入账号模版文件，一键创建账号
     * @param list
     * @return
     */
    @Override
    public int upload(List<YzUser> list) {
        int count = 0;
        for (YzUser yzUser : list) {
            yzUser.setCreateTime(DateUtils.getNowDate());
            yzUser.setUserId(snowflakeGenerator.next());
            count = yzUserMapper.insertYzUser(yzUser);
            if (count == -1){
                return -1;
            }
        }
        return count;
    }
}
